package com.sea.controller;

import com.sea.pojo.Category;
import com.sea.pojo.Result;
import com.sea.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService cs;

    @PostMapping
    public Result addC(@RequestBody @Validated(Category.Add.class) Category cg) {
        cs.add(cg);
        return Result.success();
    }

    @GetMapping
    public Result<List<Category>> list() {
        List<Category> csl = cs.getl();
        return Result.success(csl);
    }

    @GetMapping("/detail")
    public Result<Category> detail(Integer id) {
        Category c = cs.findById(id);
        return Result.success(c);
    }

    @PutMapping
    public Result updateC(@RequestBody @Validated(Category.Update.class) Category cg) {
        cs.updateC(cg);
        return Result.success();
    }

    @DeleteMapping
    public Result delete(Integer id) {
        cs.delete(id);
        return Result.success();
    }

}
